<template>
  <div class="crewactivity">
    <div class="bgg">
      <div class="card_title">
        活动列表
      </div>
      <div class="groupbox flex row_bet flex_wrap" style="margin-bottom: 19px">
        <div class="h24">
          <div class="flex row_bet flex_wrap">
            <a-radio-group v-model="status" style="margin-bottom: 5px;margin-left:5px;" @change="statusChange">
              <a-radio-button :value="1">
                在线活动
              </a-radio-button>
              <a-radio-button :value="2">
                到期活动
              </a-radio-button>
            </a-radio-group>
            <a-radio-group class="br4" v-model="sceneId" style="margin-bottom: 5px;margin-left:5px;" @change="sceneIdChange">
              <a-radio-button value="-1">
                所有类型
              </a-radio-button>
              <a-radio-button :value="1">
                普通招商
              </a-radio-button>
              <a-radio-button :value="2">
                内容招商
              </a-radio-button>
              <a-radio-button :value="3">
                品牌快抢
              </a-radio-button>
            </a-radio-group>
          </div>
        </div>
        <div class="flex row_left flex_wrap">
          <a-select
            label-in-value
            style="width: 207px;margin-right: 5px;"
            placeholder="请选择组员"
            @change="userChange"
            class="br4"
            v-model="userid"
            allowClear
          >
            <a-select-option :value="v.id" v-for="v in classList" :key="v.id">
              {{ v.user }}
            </a-select-option>
          </a-select>
          <a-input-search
            placeholder="活动id / 标题"
            style="width: 200px;margin-left:5px;margin-bottom: 5px"
            v-model="search"
            @search="onSearch"
          />
        </div>
      </div>
      <a-table
        :columns="columns"
        :rowKey="activity => activity.eventId"
        :dataSource="activity"
        :loading="loading"
        @change="handleTableChange"
        :pagination="pagination"
      >
        <div slot="sceneId" slot-scope="row">
          <div class="flex col_center">
            <span
              :style="{
                color:row.sceneId === 6 ? '#96989B' : row.sceneId === 8 ? '#2396F9': row.sceneId === 12 ?'#39C15B' : ''
              }">[{{ row.sceneId === 6 ? '普通招商' : row.sceneId === 8 ? '内容招商': row.sceneId === 12 ?'品牌快抢' : '' }}]
            </span>
            <span class="ml5">  {{ row.title }}</span>
          </div>
        </div>
        <div slot="active" slot-scope="row">
          <a-button type="link" @click="docopy(row.eventId)">链接</a-button>
          <a-button type="link" @click="goaudit(row)">审核</a-button>
        </div>
      </a-table>
    </div>
  </div>
</template>

<script>
  import { getGroupActivity, getGrounpInfo } from '@/api/teamApi'
  import moment from 'moment'

  export default {
    name: 'Crewactivity',
    data () {
      return {
        moment,
        endtime: '',
        sceneId: '-1',
        commRate: '',
        status: 1,
        search: '',
        userid: [],
        user_id: '',
        timer: [],
        titleList: [],
        classList: [],
        title_id: '',
        activity_name: '请选择活动标题',
        columns: [
          {
            title: '活动标题',
            align: 'left',
            scopedSlots: {
              customRender: 'sceneId'
            }
          },
          {
            title: '活动ID',
            // width: 150,
            align: 'center',
            dataIndex: 'eventId',
            scopedSlots: {
              customRender: 'eventId'
            }
          },
          {
            title: '开始时间',
            align: 'center',
            dataIndex: 'saveTime',
            scopedSlots: {
              customRender: 'saveTime'
            }
          },
          {
            title: '结束时间',
            align: 'center',
            // width: 500,
            dataIndex: 'endTime',
            scopedSlots: {
              customRender: 'endTime'
            }
          },
          {
            title: '活动总付款',
            align: 'center',
            dataIndex: 'price',
            scopedSlots: {
              customRender: 'price'
            }
          },
          {
            title: '团长账号',
            align: 'center',
            dataIndex: 'cpName',
            scopedSlots: {
              customRender: 'cpName'
            }
          },
          {
            title: '操作',
            align: 'center',
            scopedSlots: {
              customRender: 'active'
            }
          }
        ],
        activity: [],
        loading: false,
        pagination: {
          pageSize: 15,
          page: 1
        },
        value: '',
        btnloading: false
      }
    },

    computed: {},
    created () {
      this.getGrounpInfo()
      this.getGroupActivity(1, 15, 1)
    },
    mounted () {
    },
    methods: {
      getGrounpInfo () {
        getGrounpInfo().then(res => {
          // console.log(res)
          if (res.code === 200) {
            this.classList = res.data
          }
        }).catch(err => {
          console.log(err)
        })
      },
      userChange (value) {
        console.log(value) //
        if (value === undefined) {
          this.user_id = null
        } else {
          this.user_id = value.key
        }
        this.getGroupActivity(1, 15, this.status, this.search)
      },
      disabledEndDate (endValue) {
        if (!endValue) {
          return false
        }
        return endValue < moment().subtract(1, 'days') || endValue > moment().add(30, 'days')
      },
      sceneIdChange (e) {
        // console.log(this.sceneId)
        this.getGroupActivity(1, 15, this.status, this.search)
      },
      goaudit (row) {
        this.$store.dispatch('setRowsname', row)
        this.$router.push({
          path: '/activity/crewActivity/myAudit'
        })
      },
      docopy (id) {
        const that = this
        const str = 'http://ad.alimama.com/zhaoshang/cpevent/index.htm?srcCode=1&keyword=' + id
        this.$copyText(str).then(
          function (e) {
            // console.log(e)
            that.$success({
              title: '链接复制成功',
              content: str
            })
          },
          function (e) {
            console.log(e)
          }
        )
      },
      getGroupActivity (page, pagesize, status, search) {
        this.loading = true
        getGroupActivity({
          page: page,
          pagesize: pagesize,
          status: status, // 1有效活动 2失效活动 不传默认有效活动
          actlist_type: this.sceneId, // 1普通，2内容，3招商；（-1 全部）
          search: search,
          user_id: this.user_id
        })
          .then(res => {
            // console.log(res)
            this.activity = res.data.data
            //  this.count = res.data.count
            const pagination = {
              ...this.pagination
            }
            pagination.total = res.data.count
            this.pagination = pagination
            this.loading = false
          })
          .catch(err => {
            console.log(err)
          })
      },
      handleTableChange (pagination, filters) {
        // console.log(pagination)
        const pager = {
          ...this.pagination
        }
        pager.current = pagination.current
        this.pagination = pager
        this.fetch({
          results: pagination.pageSize,
          page: pagination.current,
          ...filters
        })
      },
      fetch (params = {}) {
        // console.log('params:', params)
        this.loading = true
        this.getGroupActivity(params.page, 15, this.status, this.search)
      },
      onSearch (value) {
        console.log(value)
        this.getGroupActivity(1, 15, this.status, this.search)
      },
      statusChange (e) {
        // console.log('radio checked', e.target.value)
        this.getGroupActivity(1, 15, this.status, this.search)
      }
    }
  }
</script>
<style lang="less" scoped>
  .crewactivity {
    .card_title {
      color: rgba(16, 16, 16, 100);
      font-size: 20px;
      margin-bottom: 18px;
      font-weight: 600;
    }
    .bgg {
      border-radius: 8px;
      margin-top: 10px;
      padding: 10px;
    }
    .groupbox {
      /deep/ .ant-input {
        border-radius: 4px;
      }
    }
    /deep/.ant-table-body{
      border: 1px solid #BBBBBB;
      border-radius: 8px 8px 0 0;
    }
    /deep/.ant-table-tbody{
      background-color: #ffffff;
    }
    /deep/.ant-table-pagination.ant-pagination{
      float: none!important;
      margin: 16px auto!important;
      text-align: center!important;
    }

  }
</style>
